package org.BUPT.infrastructure.persistent.DAO;

import org.BUPT.infrastructure.persistent.po.Question;
import org.BUPT.infrastructure.persistent.po.Subscribe;
import org.BUPT.infrastructure.persistent.po.SubscribePrimaryKey;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface SubscribeDAO extends CrudRepository<Subscribe, SubscribePrimaryKey> {
    @Query("select q " +
            "from Subscribe sc inner join Question q on sc.subscribePrimaryKey.questionId=q.id " +
            "where sc.subscribePrimaryKey.userId=:userId " +
            "and q.isDel = 0")
    List<Question> getSubscribedQuestionsByUserId(@Param("userId") int userId);
    @Query("select sc.subscribePrimaryKey.userId " +
            "from Subscribe sc " +
            "where sc.subscribePrimaryKey.questionId=:questionId ")
    List<Integer> getSubscribedUsersOfQuestion(@Param("questionId") int quesitonId);
}
